package com.youhome.clients.controller;

import com.youhome.common.exception.CustomException;
import com.youhome.common.response.Result;
import com.youhome.common.response.ResultCode;
import com.youhome.service.response.*;
import com.youhome.service.service.ZilLowByMetroService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by chen365 on 2019/04/15.
 */
@RestController
@Api(tags = "分析")
@RequestMapping("/homes/")
public class AnalysisMetroController {
    @Autowired
    private ZilLowByMetroService zilLowByMetroService;

    @ApiOperation(value = "时间序列统计分析", notes = "时间序列统计分析", response = TimeValueItemResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "type", value = "类别", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "metro", value = "都会圈", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "state", value = "州", required = true, paramType = "path")
    })
    @GetMapping(value = "/analytics/timeseries-metro/{type}/{metro}/{state}")
    public Object timeSeries(@PathVariable Integer type, @PathVariable String metro, @PathVariable String state) throws CustomException {
        return new Result<>(ResultCode.SUCCESS, zilLowByMetroService.getTimeSeriesByMetro(type, metro, state, 0));
    }

    @ApiOperation(value = "买卖指数", notes = "买卖指数", response = BuyerSellerResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "metro", value = "都会圈", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "state", value = "州", required = true, paramType = "path")
    })
    @GetMapping(value = "/analytics/buyer-seller-metro/{metro}/{state}")
    public Object buyerSeller(@PathVariable String metro, @PathVariable String state) throws CustomException {
        return new Result<>(ResultCode.SUCCESS, zilLowByMetroService.get_Buyer_Seller_Index_Metro(metro, state));
    }

    @ApiOperation(value = "房屋价格指数", notes = "房屋价格指数", response = ZhviResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "metro", value = "都会圈", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "state", value = "州", required = true, paramType = "path")
    })
    @GetMapping(value = "/analytics/price-index-metro/{metro}/{state}")
    public Object priceIndex(@PathVariable String metro, @PathVariable String state) throws CustomException {
        return new Result<>(ResultCode.SUCCESS, zilLowByMetroService.get_Metro_Zhvi_Summary_AllHomes(metro, state));
    }

    @ApiOperation(value = "租房指数", notes = "租房指数", response = ZriResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "type", value = "类别", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "metro", value = "都会圈", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "state", value = "州", required = true, paramType = "path")
    })
    @GetMapping(value = "/analytics/rent-index-metro/{type}/{metro}/{state}")
    public Object zri(@PathVariable Integer type, @PathVariable String metro, @PathVariable String state) throws CustomException {
        return new Result<>(ResultCode.SUCCESS, zilLowByMetroService.get_Metro_Zri_AllHomes_Summary(type, metro, state));
    }

    @ApiOperation(value = "市场健康指数", notes = "市场健康指数", response = MarketHealthResult.class, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "metro", value = "城市", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "state", value = "州", required = true, paramType = "path")
    })
    @GetMapping(value = "/analytics/market-health-metro/{metro}/{state}")
    public Object marketHealth(@PathVariable String metro, @PathVariable String state) throws CustomException {
        return new Result<>(ResultCode.SUCCESS, zilLowByMetroService.get_Market_Health_Index_Metro(metro, state));
    }
}
